<?php 
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {    //这是登录控制器
    public function index(){

    	$question=D('verify')->getOneVerify();//获取一条随机的人类验证
		$this->assign('question',$question);
    	$this->display();  //引入模板
		
   }
   public function checkData(){
   		$verify = I('post.verify');

        // 判断人类验证是否正确
    	if($verify != $_SESSION['answer']){
    		$arr = array(
    			'error'=>1,
    			'info'=>'人类验证不通过'
    			);
    		echo json_encode($arr);
    		exit;
    	}
    	if ($res=D('user')->checkLogin(I('post.email'),I('post.password'))){ 
            
            $_SESSION['id']=$res['id'];
            $_SESSION['nickname']=$res['nickname'];
            $_SESSION['face']=$res['face'];

    		$arr = array(
    			'error'=>0,
    			'info'=>'登录成功'
    			);
    		echo json_encode($arr);
    		exit;

    	}else{
    		$arr = array(
    			'error'=>1,
    			'info'=>'邮箱或者密码错误'
    			);
    		echo json_encode($arr);
    		exit;
    		}

   }
   public function loginout(){
        session_unset();
        session_destroy();
        $this->success('退出成功',U('home/index/index'),2);

   }

   
}


?>